#include "editor.hpp"

#include "resourcehandler.hpp"
#include "stringutil.hpp"

#include <iostream>

namespace nmc
{
    Editor::Editor()
    {
        mGui = new gcn::Gui();
        mAllegroGraphics = new gcn::AllegroGraphics();
        mGui->setGraphics(mAllegroGraphics);
        mAllegroImageLoader = new gcn::AllegroImageLoader();
        gcn::Image::setImageLoader(mAllegroImageLoader);
        mAllegroInput = new gcn::AllegroInput();
        mGui->setInput(mAllegroInput);
        mGui->addGlobalKeyListener(this);

        mFixedFont = new gcn::ImageFont(ResourceHandler::getInstance()->getRealFilename("gamefont3.bmp"), 32, 126);
		mFixedFont->setGlyphSpacing(1);
        gcn::Widget::setGlobalFont(mFixedFont);

        mTop = new gcn::Container();
        mTop->setSize(640, 480);
        mTop->setOpaque(false);
        mGui->setTop(mTop);
	
		/*
        mViewRoomCheckBox = new ImageCheckBox("icons/room.bmp");
        mViewWorldCheckBox = new ImageCheckBox("icons/world.bmp");
        mToolBarContainer  = new gcn::Container();
        mToolBarContainer->setSize(640, 25);
        mToolBarContainer->add(mViewRoomCheckBox);
        mToolBarContainer->add(mViewWorldCheckBox, mViewRoomCheckBox->getWidth(), 0);
        mToolBarContainer->setBorderSize(1);
        mTop->add(mToolBarContainer);

        mRoomEditor = new RoomEditor();
        mRoomEditor->setSize(640, 480 - 27);
        mTop->add(mRoomEditor, 0, 27);
       
        setState(WORLD);
        setRoomNumber(1);
		*/

    }

    Editor::~Editor()
    {
        delete mTop;

        delete mFixedFont;
        delete mAllegroImageLoader;
        delete mAllegroInput;
        delete mAllegroGraphics;
        delete mGui;

		/*
        delete mToolBarContainer;
        delete mViewRoomCheckBox;
        delete mViewWorldCheckBox;

        delete mRoomEditor;
		*/
    }

    void Editor::save()
    {
    }

    void Editor::logic()
    {
        mGui->logic();
    }

    void Editor::draw(BITMAP* dest)
    {
        mAllegroGraphics->setTarget(dest);
        mGui->draw();
    }

    void Editor::setRoomNumber(int roomNumber)
    {
       
       // mRoomEditor->setRoomNumber(roomNumber);
    }

    void Editor::action(const gcn::ActionEvent& actionEvent)
    {   

    }

    int Editor::getRoomNumber()
    {
        return mRoomNumber;
    }

    void Editor::setState(State state)
    {
      
    }

    void Editor::keyPressed(gcn::KeyEvent& keyEvent)
    {
		/*
        std::cout << keyEvent.getKey().getValue() << std::endl;

        // Ctrl-a
        if (keyEvent.getKey().getValue() == 1)
        {
            if (mRoomEditor->isVisible())
            {
                mRoomEditor->selectAll();
            }
        }
        // Ctrl-n
        else if (keyEvent.getKey().getValue() == 14)
        {
            if (mRoomEditor->isVisible())
            {
                mRoomEditor->selectNone();
            }
        }
        // Ctrl-r
        else if (keyEvent.getKey().getValue() == 18)
        {
            if (mRoomEditor->isVisible())
            {
                mRoomEditor->redo();
            }
        }
        // Ctrl-z
        else if (keyEvent.getKey().getValue() == 26)
        {
            if (mRoomEditor->isVisible())
            {
                mRoomEditor->undo();
            }
        }
		*/
    }
}